package com.eling.elcms.cater.service.impl;

import com.eling.elcms.cater.dao.IDishDao;
import com.eling.elcms.cater.model.Dish;
import com.eling.elcms.cater.model.Dish.State;
import com.eling.elcms.cater.service.IDishService;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishServiceImpl extends GenericManagerImpl<Dish, Long> implements IDishService{
	
	IDishDao dishDao;
	
	@Autowired
	public void setDao(IDishDao dao) {
		this.dao = dao;
		this.dishDao =dao;
	}

	@Override
	public boolean sale(Long pkDish) {
		Dish cond = new Dish();
		cond.setPkDish(pkDish);
		List<Dish> dishList = dishDao.query(cond);
		if(CollectionUtils.isNotEmpty(dishList)) {
			Dish dish = dishList.get(0);
			dish.setState(State.Sale);
			dishDao.save(dish);
			return true;
		}
		return false;
	}

	@Override
	public boolean stopSale(Long pkDish) {
		Dish cond = new Dish();
		cond.setPkDish(pkDish);
		List<Dish> dishList = dishDao.query(cond);
		if(CollectionUtils.isNotEmpty(dishList)) {
			Dish dish = dishList.get(0);
			dish.setState(State.StopSale);
			dishDao.save(dish);
			//TODO 停售包含该菜品的套餐。
			return true;
		}
		return false;
	}

	@Override
	public boolean querySetMealDish(Long pkDish) {
		//TODO 查询是否有套餐包含该菜品。
		return true;
	}
	
}
